package com.czf.testmodule.time.xxl_job;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author zfChen
 * @create 2022/6/9 15:00
 */
@Component
@Slf4j
public class DemoJob {

    private final AtomicInteger counts = new AtomicInteger();
    /**
     * 1、简单任务示例（Bean模式）
     */
    @XxlJob("demoJobHandler")
    public void demoJobHandler() throws Exception {
        XxlJobHelper.log("XXL-JOB, Hello World.");
        log.info("[execute][定时第 ({}) 次执行]", counts.incrementAndGet());
//        for (int i = 0; i < 5; i++) {
//            XxlJobHelper.log("beat at:" + i);
//            TimeUnit.SECONDS.sleep(2);
//        }
        // default success
    }
}
